home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / hardware / msec_12 / timer1.asm < prev    next >
Assembly Source File  |  1991-12-11  |  2KB  |  98 lines

  1. ;Assembly language functions extracted from TIMER.C
  2. ;and recoded in *real* assembly language.
  3. ;(Too many incompatibilities in all the different
  4. ;implementations of inline assembly language ;-)
  5. ;
  6. ;David Kirschbaum
  7. ;Toad Hall
  8.  
  9.     .MODEL    small
  10.     .CODE
  11.     PUBLIC    _initializetimer,_restoretimer,_readtimer
  12.  
  13. ;void initializetimer(void)
  14. _initializetimer    PROC    NEAR
  15. ;Old logic (very redundant):
  16. ;    mov    dx,43H        ;/* outp(0x043,0x034); */
  17. ;    mov    al,34H
  18. ;    out    dx,al
  19. ;    jmp    short $+2
  20. ;
  21. ;    mov    dx,40H        ;/* outp(0x040,0x000); */
  22. ;    xor    ax,ax
  23. ;    out    dx,al
  24. ;    jmp    short $+2
  25. ;
  26. ;    out    dx,al        ;/* outp(0x040,0x000); */
  27. ;    ret
  28.  
  29.     mov    al,34H
  30.     jmp    short Common    ;common to return
  31.  
  32. _initializetimer    ENDP
  33.  
  34.  
  35. ;void restoretimer(void)
  36.  
  37. _restoretimer    PROC    NEAR
  38.     mov    al,36H        ;/* outp(0x043,0x036); */
  39. Common:
  40.     mov    dx,43H
  41.     out    dx,al
  42.     jmp    short $+2
  43.  
  44.     mov    dx,40H        ;/* outp(0x040,0x000); */
  45.     xor    ax,ax
  46.     out    dx,al
  47.     jmp    short $+2
  48.  
  49.     out    dx,al        ;/* outp(0x040,0x000); */
  50.     ret
  51. _restoretimer    ENDP
  52.  
  53. ;long readtimer(void)
  54. _readtimer    PROC    NEAR
  55.     push    si        ;save these just in case
  56.     push    di
  57.  
  58.     cli            ;/* Disable interrupts */
  59.     mov    dx,020h        ;/* Address PIC ocw3   */
  60.     mov    al,00Ah        ;/* Ask to read irr    */
  61.     out    dx,al
  62.     mov    al,00h        ;/* Latch timer 0 */
  63.     out    043h,al
  64.     in    al,dx        ;/* Read irr      */
  65.     mov    di,ax        ;/* Save it in DI */
  66.     in    al,040h        ;/* Counter --> bx*/
  67.     mov    bl,al        ;/* LSB in BL     */
  68.     in    al,040h
  69.     mov    bh,al        ;/* MSB in BH     */
  70.     not    bx        ;/* Need ascending counter */
  71.     in    al,021h        ;/* Read PIC imr  */
  72.     mov    si,ax        ;/* Save it in SI */
  73.  
  74.     mov    al,00FFh    ;/* Mask all interrupts */
  75.     out    021h,al
  76.     mov    ax,040h        ;/* read low word of time */
  77.     mov    es,ax        ;/* from BIOS data area   */
  78.     mov    dx,es:[06Ch]    ;here's the timer long.hi
  79.  
  80.     mov    ax,si        ;/* Restore imr from SI   */
  81.     out    021h,al
  82.  
  83.     sti            ;/* Enable interrupts */
  84.     mov    ax,di        ;/* Retrieve old irr  */
  85.     test    al,001h        ;/* Counter hit 0?    */
  86.     jz    Done        ;/* Jump if not       */
  87.     cmp    bx,0FFh        ;/* Counter > 0x0FF?    */
  88.     ja    Done        ;/* Done if so        */
  89.      inc    dx        ;/* Else count int req. */
  90. Done:    mov    ax,bx        ;/* set function result */
  91.  
  92.     pop    di        ;restore
  93.     pop    si
  94.     ret
  95. _readtimer    ENDP
  96.  
  97.     END
  98.